const friendlyError = require('./build/friendly-error')
const webpackConfig = require('./build/webpack.dev')(__dirname)
const getIPAdress = require('./build/get-ip-adress')

webpackConfig.entry.main = ['@/assets/iconfont-link.dev.css', '@/modules/ajax-mid/test.js'].concat(webpackConfig.entry.main)

// proxy 文档：https://github.com/chimurai/http-proxy-middleware
webpackConfig.devServer.proxy = {
  '/online': {
    target: 'https://api.shendupeiban.com',
    pathRewrite: {
      '^/online': ''
    },

    // 注意以下的自定义无法在浏览器端看到，因为是通过nodejs去请求的，而不是浏览器。所以只能在服务端看到

    // 允许服务端重定向
    followRedirects: true,
    // 重写 host。以 target 重写
    changeOrigin: true,
    // 直接修改 headers
    // headers: {
    //   Cookie: 'ASP.NET_SessionId=nwlyo2azpq3zhimw4vgz0fqo; .ASPXAUTH=',
    //   Host: '192.168.1.110:8787',
    //   Origin: 'http://192.168.1.110:8787',
    //   'Upgrade-Insecure-Requests': 1,
    //   'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'
    // }
  },
  '/162': {
    target: "http://192.168.1.162:8087",
    pathRewrite: {
      '^/mock': ''
    },
  },
  '/mock': {
    target: `http://${getIPAdress()}:3003`,
    pathRewrite: {
      '^/mock': ''
    },
  },
  '/postman': {
    target: `https://f7c89f9e-24fb-4ecc-b738-a8e9b9eb8974.mock.pstmn.io`,
    followRedirects: true,
    // 重写 host。以 target 重写
    changeOrigin: true,
    pathRewrite: {
      '^/postman': ''
    },
  }, 
}

module.exports = friendlyError(webpackConfig)
